
function saveInformation() {
	
	var registered_capital =$("#registered_capital").val()
	if(!registered_capital){
		registered_capital=null;
	}else{
		registered_capital = parseFloat(registered_capital.replace(/\,/g,""))
	}
	var paid_in_capital = $("#paid_in_capital").val()
	if(!paid_in_capital){
		paid_in_capital=null;
	}else{
		paid_in_capital = parseFloat(paid_in_capital.replace(/\,/g,""))
	}
	$.ajax({
		type : "POST",
		url : "updatedebtor",
		data : {
			id : $("#id").val(),
			debtor_name : $("#debtor_name").val(),
			debtor_sex : $("#debtor_sex").val(),
			debtor_age : $("#debtor_age").val(),
			debtor_card_id : $("#debtor_card_id").val(),
			residence_address : $("#residence_address").val(),
			current_residence : $("#current_residence").val(),
			management_state : $("#management_state").val(),
			unified_social_code : $("#unified_social_code").val(),
			registered_capital : registered_capital,
			paid_in_capital : paid_in_capital,
			limit_highest : $("#limit_highest").val(),
			limit_highest_code : $("#limit_highest_code").val(),
			entry_and_exit_restrictions : $("#entry_and_exit_restrictions").val(),
		},
		dataType : 'json',
		success : function(result) {
			console.log(result);
			if(result.status == 200){
				alert("保存成功");
			} else {
				alert("保存失败");
			}
		},
	});
}
$(document).on("change", "#limit_highest", function() {
	var limit_highest = $("#limit_highest").val();
	if(limit_highest == 0){
		$("#limit_highest_chose").hide()
	} else {
		$("#limit_highest_chose").show();
	}
})
$(document).on("click", "[name='close']", function() {
	var id = $(this).parent().parent()[0].id.split("_")[1];
	console.log(id);
	/* console.log($(this).parent().parent()[0].id); */
	// debugger;
	if (typeof (id) != "undefined") {
		$.ajax({
			type : "POST",
			url : "deletetelephone",
			data : {
				telephoneid : id
			},
			dataType : 'json',
			success : function(result) {
				if (result.code == '1') {
					$("#phone_" + id).remove();
					alert("删除成功");
				} else {
					alert("删除失败");
				}
			},
		});
	} else {
		$(this).parent().parent().remove();
	}
})

function save() {
	saveInformation();
	console.log($("[name='debtor_phone_add']").val());
	var id = $("#id").val()
	console.log($("[name='debtor_zhifubao_state_add]").val());
	$.ajax({
		type : "POST",
		url : "addtelephone",
		data : {
			debtorid : id,
			debtor_phone : $("[name='debtor_phone_add']").val(),
			phone_status : $("[name='debtor_phone_state_add']").val(),
			wechat_status : $("#debtor_wexin_state_add").val(),
			alipay_status : $("#debtor_zhifubao_state_add").val()
		},
		dataType : 'json',
		success : function(result) {
			console.log(result);
			if (result.status == 200) {
				$("#inform").load(location.href + " #inform");
				$("#modal-form").modal('hide');
				$('.modal-backdrop').remove();// 去掉遮罩层
				alert("保存成功");
			} else {
				alert("保存失败");
			}
		},
	});
}

function cancel() {
	$("#modal-form").hide();
}

function saveHouse() {
	var h_preservation_amount = $("#h_preservation_amount").val()
	if(!h_preservation_amount){
		h_preservation_amount=null;
	}else{
		h_preservation_amount = parseFloat(h_preservation_amount.replace(/\,/g,""))
	}
	var h_guarantee_amount = $("#h_guarantee_amount").val()
	if(!h_guarantee_amount){
		h_guarantee_amount=null;
	}else{
		h_guarantee_amount = parseFloat(h_guarantee_amount.replace(/\,/g,""))
	}
	var mortgage_start_date = $("#mortgage_start_date").val()
	var id = $("#id").val()
	var valuation = $("#valuation").val()
	if(!valuation){
		valuation=null;
	}else{
		valuation = parseFloat(valuation.replace(/\,/g,""))
	}
	var house_pawn_amount = $("#house_pawn_amount").val()
	if(!house_pawn_amount){
		house_pawn_amount=null;
	}else{
		house_pawn_amount = parseFloat(house_pawn_amount.replace(/\,/g,""))
	}
	var house_auction_pawn_amount = $("#house_auction_pawn_amount").val()
	if(!house_auction_pawn_amount){
		house_auction_pawn_amount = null
	}else{
		house_auction_pawn_amount = parseFloat(house_auction_pawn_amount.replace(/\,/g,""))
	}
	var house_auction_assess = $("#house_auction_assess").val()
	if(!house_auction_assess){
		house_auction_assess = null
	}else{
		house_auction_assess = parseFloat(house_auction_assess.replace(/\,/g,""))
	}
	$.ajax({
		type : "POST",
		url : "addhouse",
		data : {
			debtor_id : id,
			property_ownership_certificate_code : $(
					"#property_ownership_certificate_code").val(),
			property_owner_name : $("[name='property_owner_name']").val(),
			hourse_address : $("#hourse_address").val(),
			mortgage_status : $("#mortgage_status").val(),
			seal_status : $("#seal_status").val(),
			written_verdict : $("#written_verdict").val(),
			preservation_amount : h_preservation_amount,
			guarantee_amount : h_guarantee_amount,
			preservation_start_date : $("#preservation_start_date").val(),
			preservation_end_date : $("#preservation_end_date").val(),
			acreage : $("#acreage").val(),
			option_person:$("#house_option_person").val(),
			pawn_amount: house_pawn_amount,
			valuation : valuation,
			mortgage_start_date : mortgage_start_date,
			mortgage_end_date : $("#mortgage_end_date").val(),
			other_mortgage_status : $("#other_mortgage_status").val(),
			house_auction_assess : house_auction_assess,
			auction_status : $("#auction_status").val(),
			auction_date : $("#auction_date").val(),
			auction_notice : $("#auction_notice").val(),
			auction_assess_status : $("#auction_assess_status").val(),
			house_auction_result : $("#house_auction_result").val(),
			house_auction_pawn_amount : house_auction_pawn_amount
			
		},
		dataType : 'json',
		success : function(result) {
			console.log(result);
			if (result.status == 200) {
				$("#modal-form-house").modal('hide');
				$('.modal-backdrop').remove();// 去掉遮罩层
				$("#t1").load(location.href + " #t1");
				alert("保存成功");
			} else {
				alert("保存失败");
			}
		},
	});
}

function cancelHouse() {
	$("#modal-form-house").hide();
}


function cancelCar() {
	$("#modal-form-car").hide();
}

function saveCompany() {
	
	var c_preservation_amount =$("#c_preservation_amount").val()
	if(!c_preservation_amount){
		c_preservation_amount=null;
	}else{
		c_preservation_amount = parseFloat(c_preservation_amount.replace(/\,/g,""))
	}
	var c_guarantee_amount =$("#c_guarantee_amount").val()
	if(!c_guarantee_amount){
		c_guarantee_amount=null;
	}else{
		c_guarantee_amount = parseFloat(c_guarantee_amount.replace(/\,/g,""))
	}
	var company_pawn_amount = $("#company_pawn_amount").val()
	if(!company_pawn_amount){
		company_pawn_amount=null;
	}else{
		company_pawn_amount = parseFloat(company_pawn_amount.replace(/\,/g,""))
	}
	var company_auction_assess = $("#company_auction_assess").val()
	if(!company_auction_assess){
		company_auction_assess= null
	}else{
		company_auction_assess = parseFloat(company_auction_assess.replace(/\,/g,""))
	}
	var company_auction_pawn_amount = $("#company_auction_pawn_amount").val()
	if(!company_auction_pawn_amount){
		company_auction_pawn_amount = null
	}else{
		company_auction_pawn_amount = parseFloat(company_auction_pawn_amount.replace(/\,/g,""))
	}
	var id = $("#id").val()
	$.ajax({
		type : "POST",
		url : "addcompany",
		data : {
			debtor_id : id,
			company_name : $("#company_owner_name").val(),
			registration_number : $("#company_registration_number").val(),
			license_number : $("#company_license_number").val(),
			business_entity : $("#company_business_entity").val(),
			company_address : $("#company_address").val(),
			management_address : $("#management_address").val(),
			mortgage_status : $("#company_mortgage_status").val(),
			seal_status_info : $("#company_seal_status_info").val(),
			seal_status : $("#company_seal_status").val(),
			stock_ratio : $("#stock_ratio").val(),
			written_verdict : $("#company_written_verdict").val(),
			preservation_amount : c_preservation_amount,
			guarantee_amount : c_guarantee_amount,
			preservation_start_date : $("#company_preservation_start_date").val(),
			preservation_end_date : $("#company_preservation_end_date").val(),
			option_person:$("#company_option_person").val(),
			pawn_amount: company_pawn_amount,
			company_mortgage_start_date : $("#company_mortgage_start_date").val(),
			company_mortgage_end_date : $("#company_mortgage_end_date").val(),
			company_other_mortgage_status : $("#company_other_mortgage_status").val(),
			company_auction_status : $("#company_auction_status").val(),
			company_auction_date : $("#company_auction_date").val(),
			company_auction_notice : $("#company_auction_notice").val(),
			company_auction_assess_status : $("#company_auction_assess_status").val(),
			company_auction_assess : company_auction_assess,
			company_auction_result : $("#company_auction_result").val(),
			company_auction_pawn_amount : company_auction_pawn_amount
		},

		success : function(result) {
			console.log(result);
			if (result.code != '0') {
				$("#t2").load(location.href + " #t2");
				$("#modal-form-company").modal('hide');
				$('.modal-backdrop').remove();// 去掉遮罩层
				alert("保存成功");
			} else {
				alert("保存失败");
			}
		},
	});
}


function saveHousePreservation() {
	var h_written_verdict = $("#h_written_verdict").val()
	if(!h_written_verdict){
		toastr.error('请填写财保裁定书')
		return;
	}
	var preservation_amount = $("#h_other_preservation_amount").val()
	if(!preservation_amount){
		preservation_amount=null;
	}else{
		preservation_amount = parseFloat(preservation_amount.replace(/\,/g,""))
	}
	var guarantee_amount = $("#h_other_guarantee_amount").val()
	if(!guarantee_amount){
		guarantee_amount=null;
	}else{
		guarantee_amount = parseFloat(guarantee_amount.replace(/\,/g,""))
	}
	var id = $("#house_preservation_id").attr("data-id");
	$.ajax({
		type : "POST",
		url : "addHousePreservation",
		data : {
			property_id : id,
			written_verdict : h_written_verdict,
			preservation_amount : preservation_amount,
			guarantee_amount : guarantee_amount,
			preservation_start : $("#h_preservation_start").val(),
			preservation_end : $("#h_preservation_end").val(),
			note : $("#h_note").val(),
		},

		success : function(result) {
			console.log(result);
			if (result.code != '0') {
				$("#t1").load(location.href + " #t1");
				$("#house_preservation").modal('hide');
				$('.modal-backdrop').remove();// 去掉遮罩层
				alert("保存成功");
			} else {
				alert("保存失败");
			}
		},
	});

}
function saveCarPreservation() {
	var car_written_verdict = $("#cars_written_verdict").val()
	if(!car_written_verdict){
		toastr.error('请填写财保裁定书')
		return;
	}
	var preservation_amount = $("#car_other_preservation_amount").val()
	if(!preservation_amount){
		preservation_amount=null;
	}else{
		preservation_amount = parseFloat(preservation_amount.replace(/\,/g,""))
	}
	var guarantee_amount = $("#car_other_guarantee_amount").val()
	if(!guarantee_amount){
		guarantee_amount=null;
	}else{
		guarantee_amount = parseFloat(guarantee_amount.replace(/\,/g,""))
	}
	var id = $("#car_preservation_id").attr("data-id");
	$.ajax({
		type : "POST",
		url : "addCarPreservation",
		data : {
			property_id : id,
			written_verdict : car_written_verdict,
			preservation_amount : preservation_amount,
			guarantee_amount : guarantee_amount,
			preservation_start : $("#cars_preservation_start").val(),
			preservation_end : $("#cars_preservation_end").val(),
			note : $("#cars_note").val(),
		},

		success : function(result) {
			console.log(result);
			if (result.code != '0') {
				$("#t3").load(location.href + " #t3");
				$("#car_preservation").modal('hide');
				$('.modal-backdrop').remove();// 去掉遮罩层
				alert("保存成功");
			} else {
				alert("保存失败");
			}
		},
	});
}

function saveBankPreservation() {
	var bank_written_verdict = $("#banks_written_verdict").val()
	if(!bank_written_verdict){
		toastr.error('请填写财保裁定书')
		return;
	}
	var preservation_amount = $("#bank_other_preservation_amount").val()
	if(!preservation_amount){
		preservation_amount=null;
	}else{
		preservation_amount = parseFloat(preservation_amount.replace(/\,/g,""))
	}
	var guarantee_amount = $("#bank_other_guarantee_amount").val()
	if(!guarantee_amount){
		guarantee_amount=null;
	}else{
		guarantee_amount = parseFloat(guarantee_amount.replace(/\,/g,""))
	}
	var id = $("#bank_preservation_id").attr("data-id");
	$.ajax({
		type : "POST",
		url : "addBankPreservation",
		data : {
			property_id : id,
			written_verdict : bank_written_verdict,
			preservation_amount : preservation_amount,
			guarantee_amount : guarantee_amount,
			preservation_start : $("#bank_preservation_start").val(),
			preservation_end : $("#bank_preservation_end").val(),
			note : $("#bank_note").val(),
		},

		success : function(result) {
			console.log(result);
			if (result.code != '0') {
				$("#t4").load(location.href + " #t4");
				$("#bank_preservation").modal('hide');
				$('.modal-backdrop').remove();// 去掉遮罩层
				alert("保存成功");
			} else {
				alert("保存失败");
			}
		},
	});
}
function saveCompanyPreservation() {
	var c_written_verdict = $("#c_written_verdict").val()
	if(!c_written_verdict){
		toastr.error('请填写财保裁定书')
		return;
	}
	var preservation_amount = $("#c_other_preservation_amount").val()
	if(!preservation_amount){
		preservation_amount=null;
	}else{
		preservation_amount = parseFloat(preservation_amount.replace(/\,/g,""))
	}
	var guarantee_amount = $("#c_other_guarantee_amount").val()
	if(!guarantee_amount){
		guarantee_amount=null;
	}else{
		guarantee_amount = parseFloat(guarantee_amount.replace(/\,/g,""))
	}
	
	var id = $("#company_preservation_id").attr("data-id");
	$.ajax({
		type : "POST",
		url : "addCompanyPreservation",
		data : {
			property_id : id,
			written_verdict : c_written_verdict,
			preservation_amount : preservation_amount,
			guarantee_amount : guarantee_amount,
			preservation_start : $("#c_preservation_start").val(),
			preservation_end : $("#c_preservation_end").val(),
			note : $("#c_note").val(),
		},

		success : function(result) {
			console.log(result);
			if (result.code != '0') {
				$("#t2").load(location.href + " #t2");
				$("#company_preservation").modal('hide');
				$('.modal-backdrop').remove();// 去掉遮罩层
				alert("保存成功");
			} else {
				alert("保存失败");
			}
		},
	});

}
function cancelCompany() {
	$("#modal-form-company").hide();
}

function edit(phoneid) {
	console.log(phoneid)
}

function deletehouse(id) {
	var data = {
		id : id
	};
	$.ajax({
		type : "get",
		url : "deletehousebyid",
		data : {
			houseid : id
		},
		dataType : 'json',
		success : function(data) {
			if (data.code == '1') {
				$("#t1").load(location.href + " #t1");
				alert("删除成功");

			} else {
				alert("删除失败");
			}
		}
	});
}

function deletecompany(id) {
	var data = {
		id : id
	};
	$.ajax({
		type : "get",
		url : "deletecompanybyid",
		data : {
			comid : id
		},
		dataType : 'json',
		success : function(data) {
			if (data.code == '1') {
				$("#t2").load(location.href + " #t2");
				alert("删除成功");
			} else {
				alert("删除失败");
			}
		}
	});
}

function deletecar(id) {
	var data = {
		id : id
	};
	$.ajax({
		type : "get",
		url : "deletecarbyid",
		data : {
			carid : id
		},
		dataType : 'json',
		success : function(data) {
			if (data.code == '1') {
				$("#t3").load(location.href + " #t3");
				alert("删除成功");

			} else {
				alert("删除失败");
			}
		}
	});
}

function deletebank(id) {
	var data = {
		id : id
	};
	$.ajax({
		type : "get",
		url : "deletebanksbyid",
		data : {
			bankid : id
		},
		dataType : 'json',
		success : function(data) {
			if (data.code == '1') {
				$("#t4").load(location.href + " #t4");
				alert("删除成功");

			} else {
				alert("删除失败");
			}
		}
	});
}
function saveBank() {
	var b_preservation_amount = $("#b_preservation_amount").val()
	if(!b_preservation_amount){
		b_preservation_amount=null;
	}else{
		b_preservation_amount = parseFloat(b_preservation_amount.replace(/\,/g,""))
	}
	var b_guarantee_amount = $("#b_guarantee_amount").val()
	if(!b_guarantee_amount ){
		b_guarantee_amount  = null
	}else{
		b_guarantee_amount  = parseFloat(b_guarantee_amount.replace(/\,/g,""))
	}
	var id = $("#id").val()
	$.ajax({
		type : "POST",
		url : "addbank",
		data : {
			debtor_id : id,
			account_name : $("#account_name").val(),
			opening_bank : $("#opening_bank").val(),
			account : $("#account").val(),
			seal_status : $("#seal_status").val(),
			seal_status_info : $("#seal_status_info").val(),
			note : $("#note").val(),
			written_verdict:$("#bank_written_verdict").val(),
			b_preservation_amount : b_preservation_amount,
			b_guarantee_amount : b_guarantee_amount,
			preservation_start_date:$("#bank_preservation_start_date").val(),
			preservation_end_date:$("#bank_preservation_end_date").val()
		},
		dataType : 'json',
		success : function(result) {
			console.log(result);
			if (result.code != '0') {
				$("#t4").load(location.href + " #t4");
				$("#modal-form-bank").modal('hide');
				$('.modal-backdrop').remove();// 去掉遮罩层
				alert("保存成功");
			} else {
				alert("保存失败");
			}
		},
	});
}

function change_house_mortgage_status(){
	var mortgage_status = $("#mortgage_status").val();
	if(mortgage_status == 1){
		$("#house_option_person").val("");
		$("#house_pawn_amount").val("");
		$("#house_had_mortgage").hide();
	} else {
		$("#house_had_mortgage").show();
	}
}
function change_house_auction_status(){
	var auction_status = $("#auction_status").val();
	if(auction_status == 1){
		$("#auction_date").val("");
		$("#house_pawn_amount").val("");
		$("#house_had_auction").hide();
	} else {
		$("#house_had_auction").show();
	}
}
function house_assess_status(){
	var auction_assess = $("#auction_assess_status").val();
	if(auction_assess == 1){
		$("#house_auction_assess").val("");
		$("#house_assess_valuation_status").hide();
		$("#house_assess_valuation_statusx").show();
	} else {
		$("#house_assess_valuation_status").show();
		$("#house_assess_valuation_statusx").hide();
	}
}
function change_company_mortgage_status(){
	var mortgage_status = $("#company_mortgage_status").val();
	if(mortgage_status == 1){
		$("#company_option_person").val("");
		$("#company_pawn_amount").val("");
		$("#company_had_mortgage").hide();
	} else {
		$("#company_had_mortgage").show();
	}
}
function change_company_auction_status(){
	var company_auction_status = $("#company_auction_status").val();
	if(company_auction_status == 1){
		$("#company_auction_date").val("");
		$("#company_auction_pawn_amount").val("");
		$("#company_had_auction").hide();
	} else {
		$("#company_had_auction").show();
	}
}
function company_assess_status(){
	var company_auction_assess_status = $("#company_auction_assess_status").val();
	if(company_auction_assess_status == 1){
		$("#company_auction_assess").val("");
		$("#company_assess_valuation_status").hide();
		$("#company_assess_valuation_statusx").show();
	} else {
		$("#company_assess_valuation_status").show();
		$("#company_assess_valuation_statusx").hide();
	}
}
function change_car_mortgage_status(){
	var mortgage_status = $("#car_mortgage_status").val();
	if(mortgage_status == 1){
		$("#car_option_person").val("");
		$("#car_pawn_amount").val("");
		$("#car_had_mortgage").hide();
	} else {
		$("#car_had_mortgage").show();
	}
}
function change_car_auction_status(){
	var car_auction_status = $("#car_auction_status").val();
	if(car_auction_status == 1){
		$("#car_auction_date").val("");
		$("#car_auction_pawn_amount").val("");
		$("#car_had_auction").hide();
	} else {
		$("#car_had_auction").show();
	}
}
function car_assess_status(){
	var car_auction_assess_status = $("#car_auction_assess_status").val();
	if(car_auction_assess_status == 1){
		$("#car_auction_assess").val("");
		$("#car_assess_valuation_status").hide();
		$("#car_assess_valuation_statusx").show();
	} else {
		$("#car_assess_valuation_status").show();
		$("#car_assess_valuation_statusx").hide();
	}
}

function saveCar() {
	var car_preservation_amount = $("#car_preservation_amount").val()
	if(!car_preservation_amount){
		car_preservation_amount=null;
	}else{
		car_preservation_amount = parseFloat(car_preservation_amount.replace(/\,/g,""))
	}
	var car_guarantee_amount = $("#car_guarantee_amount").val()
	if(!car_guarantee_amount ){
		car_guarantee_amount  = null
	}else{
		car_guarantee_amount  = parseFloat(car_guarantee_amount.replace(/\,/g,""))
	}
	var id = $("#id").val()	
	var car_note = $("#car_note").val()
	var car_pawn_amount = $("#car_pawn_amount").val()
	if(!car_pawn_amount){
		car_pawn_amount=null;
	}else{
		car_pawn_amount = parseFloat(car_pawn_amount.replace(/\,/g,""))
	}
	var car_auction_pawn_amount = $("#car_auction_pawn_amount").val()
	if(!car_auction_pawn_amount){
		car_auction_pawn_amount = null
	}else{
		car_auction_pawn_amount = parseFloat(car_auction_pawn_amount.replace(/\,/g,""))
	}
	var car_auction_assess = $("#car_auction_assess").val()
	if(!car_auction_assess){
		car_auction_assess = null
	}else{
		car_auction_assess = parseFloat(car_auction_assess.replace(/\,/g,""))
	}
	$.ajax({
		type : "POST",
		url : "addcar",
		data : {
			debtor_id : id,
			car_owner_name : $("#car_owner_name").val(),
			brand : $("#brand").val(),
			car_code : $("#car_code").val(),
			car_note : car_note,
			mortgage_status : $("#car_mortgage_status").val(),
			seal_status : $("#car_seal_status").val(),
			written_verdict : $("#car_written_verdict").val(),
			car_preservation_amount : car_preservation_amount,
			car_guarantee_amount : car_guarantee_amount,
			preservation_start_date : $("#car_preservation_start_date").val(),
			preservation_end_date : $("#car_preservation_end_date").val(),
			option_person:$("#car_option_person").val(),
			pawn_amount: car_pawn_amount,
			car_mortgage_start_date : $("#car_mortgage_start_date").val(),
			car_mortgage_end_date : $("#car_mortgage_end_date").val(),
			car_other_mortgage_status : $("#car_other_mortgage_status").val(),
			car_auction_status : $("#car_auction_status").val(),
			car_auction_date : $("#car_auction_date").val(),
			car_auction_notice : $("#car_auction_notice").val(),
			car_auction_assess_status : $("#car_auction_assess_status").val(),
			car_auction_assess : car_auction_assess,
			car_auction_result : $("#car_auction_result").val(),
			car_auction_pawn_amount : car_auction_pawn_amount
		},
		success : function(result) {
			console.log(result);
			if (result.code != '0') {
				$("#t3").load(location.href + " #t3");
				$("#modal-form-car").modal('hide');
				$('.modal-backdrop').remove();// 去掉遮罩层
				alert("保存成功");
			} else {
				alert("保存失败");
			}
		},
	});

}
